<?php

namespace App\Controller\Api\Wuliu;

use App\Base\BaseController4Restful;
use App\Repository\MoneyStaticRepository;
use App\Repository\Wuliu\WuliuOrderRepository;
use App\Repository\Wuliu\WuliuUserRepository;
use Symfony\Component\Routing\Annotation\Route;

class ApiWuliuUserHomeController extends BaseController4Restful
{
    /**
     * @Route("/api/wuliu/user/home", name="apiWuliuUsersHome")
     */
    public function apiWuliuUsersHome(
        WuliuOrderRepository $wuliuOrderRepository,
        MoneyStaticRepository $moneyStaticRepository,
        WuliuUserRepository $wuliuUserRepository
    )
    {
        $user = $this->getUser();
        $data = [];
        //发布订单
        $data["order"] = $wuliuOrderRepository->count(array(
            "user"=>$wuliuUserRepository->getByUser($user),
            "status"=>9
        ));
        //邀请用户
        $data["sons"] = $user->getSons()->count();
        //累计返佣
        //---红包返现
        $data["money"]
            = $moneyStaticRepository->getUserMoneyStaticByTypeId($user,2,110)->getMoney()
            + $moneyStaticRepository->getUserMoneyStaticByTypeId($user,2,111)->getMoney() ;

        return $this->json_out(1,"OK",$data);
    }
}
